﻿using Azure.Core;
using B.S.BasicData.Api.Write.Application.Command.Account;
using B.S.BasicData.Api.Write.Application.Command.GridPerson;
using B.S.BasicData.Api.Write.DTOs;
using B.S.BasicData.Api.Write.InnerApi;
using B.S.BasicData.Domain.Entities;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// 账号控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ServiceDiscovery service;

        public AccountController(IMediator mediator,ServiceDiscovery service)
        {
            this.mediator = mediator;
            this.service = service;
        }

        /// <summary>
        /// 创建账号-接口
        /// </summary>
        /// <param name="request">账号请求命令(参数)</param>
        /// <returns></returns>
        [HttpPost]
        public  Task<ApiResult<int>> CreateAccount(CreateAccountCommand request) { 
            return mediator.Send(request);
        }
        
        /// <summary>
        /// 更新头像后端接口
        /// </summary>
        /// <param name="request">账号请求命令(参数)</param>
        /// <returns></returns>
        [HttpPut]
        public  Task<ApiResult<int>> UpadateAccountImg(UpadateAccountImgCommand request) { 
            return mediator.Send(request);
        }

        /// <summary>
        /// 通过consul获取地址,直接调用内部接口
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPaging<AccountListDTO>> GetAccount() {

            var url =await service.GetUrl("B.S.BasicData.Api.Read", "/api/Account/GetAccountPage");
            var res =await service.GetAccount(url);
            return res;
        }


    }
}
